#pragma once
#include "cvxImage.h"
#include "afxwin.h"
#include "afxcmn.h"
#include "RigCalib.h"
#include <string>
#include "cvxBoard.h"

using std::string;

// CGrabItem command target

class CGrabItem : public CObject
{
public:
	CGrabItem(IplImage *pLeft, IplImage *pRight);
	~CGrabItem();

	//added
	bool GetCorner(bool accurate, const CvxBoard *board);

public:
	IplImage *m_leftImage;
	IplImage *m_rightImage;
	vector<Point2f> m_leftPts;
	vector<Point2f> m_rightPts;
//	vector<Point3f> m_leftPts3D;
//	vector<Point3f> m_rightPts3D;

};


// CGrabList dialog

class CGrabList : public CDialog
{
	DECLARE_DYNAMIC(CGrabList)

public:
	CGrabList(CWnd* pParent = NULL);   // standard constructor
	virtual ~CGrabList();

	//added
	CList<CGrabItem*> m_itemList;
	CvxBoard *m_board;             //pattern configuration

// Dialog Data
	enum { IDD = IDD_GRAB_LIST };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

	DECLARE_MESSAGE_MAP()
	// point to parent, set parent->this = NULL when this is released
	CWnd* m_pParent;

public:
	afx_msg void OnBnClickedOk();
	afx_msg void OnBnClickedCancel();
protected:
	virtual void PostNcDestroy();
public:
	// add image pair to grab list
	void AddList(int framNum, IplImage * left, IplImage * right);
	// update reprojection error from rig calib
	void updateReprojectionError(const vector<float> &left, const vector<float> &right);
	// display orientation for extrinsic parameters
	void updateOrientation(const vector<float> &theta, const vector<float> &phi, 
						   const vector<float> &z_dis, const vector<float> &rod,
						   const vector<Vec3d> &normalVec,
						   bool isLeft);

	virtual BOOL OnInitDialog();
protected:

	CListCtrl m_controlList;
public:
	// rig calibration, which calibrate left and right camera from image sequences
	CRigCalib *m_rigCalib;
	afx_msg void OnBnClickedGrabListRigCalibration();
	afx_msg void OnNMDblclkGrabListListControl(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnBnClickedGrablistSaveImg();
	afx_msg void OnBnClickedGrablistLoadimg();
	afx_msg void OnNMRClickGrabListListControl(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnGriditempopupDelete();
	afx_msg void OnBnClickedAddImages();
protected:

	//pattern type checker board or marker concentric circles board
	CComboBox m_patternType;
public:
protected:
	CComboBox m_patternSize;
public:
	afx_msg void OnCbnSelchangeComboPatternType();
protected:
	CComboBox m_unitLength;
public:
	afx_msg void OnBnClickedButtonSetPattern();
	afx_msg void OnBnClickedGrablistSavePts();
};
#pragma once




